from sqlalchemy import create_engine
from sqlalchemy.orm.session import sessionmaker
from sqlalchemy.orm import scoped_session

from base import Base
from .User import *
from .Permission import *
from .Role import *
from .Account import *
from .Money import *
from .Currency import *

metadata = Base.metadata

USER = "root"
PSWD = "rootpswd"
HOST = "localhost"
DATABASE = "homebuh"

URL = "mysql://%s:%s@%s/%s?charset=utf8" % (USER, PSWD, HOST, DATABASE)

engine = create_engine(URL, encoding="utf8", echo=True)
_Session = scoped_session(sessionmaker(bind=engine, autocommit=True))

def getSession():
    return _Session()

def create_db():
    metadata.create_all(engine)
    
def dropTables():
    metadata.drop_all(engine)